<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>RSA_set_method</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>



<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="#THE-RSA_METHOD-STRUCTURE">THE RSA_METHOD STRUCTURE</a></li>
  <li><a href="#RETURN-VALUES">RETURN VALUES</a></li>
  <li><a href="#BUGS">BUGS</a></li>
  <li><a href="#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="#HISTORY">HISTORY</a></li>
  <li><a href="#COPYRIGHT">COPYRIGHT</a></li>
</ul>

<h1 id="NAME">NAME</h1>

<p>RSA_set_default_method, RSA_get_default_method, RSA_set_method, RSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags, RSA_new_method - select RSA method</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code> <span class="comment">#include &lt;openssl/rsa.h&gt;</span>
 
 <span class="variable">void</span> <span class="variable">RSA_set_default_method</span><span class="operator">(</span><span class="variable">const</span> <span class="variable">RSA_METHOD</span> <span class="variable">*meth</span><span class="operator">);</span>
 
 <span class="variable">RSA_METHOD</span> <span class="variable">*RSA_get_default_method</span><span class="operator">(</span><span class="variable">void</span><span class="operator">);</span>
 
 <span class="keyword">int</span> <span class="variable">RSA_set_method</span><span class="operator">(</span><span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">RSA_METHOD</span> <span class="variable">*meth</span><span class="operator">);</span>
 
 <span class="variable">RSA_METHOD</span> <span class="variable">*RSA_get_method</span><span class="operator">(</span><span class="variable">const</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">);</span>
 
 <span class="variable">RSA_METHOD</span> <span class="variable">*RSA_PKCS1_OpenSSL</span><span class="operator">(</span><span class="variable">void</span><span class="operator">);</span>
 
 <span class="keyword">int</span> <span class="variable">RSA_flags</span><span class="operator">(</span><span class="variable">const</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">);</span>
 
 <span class="variable">RSA</span> <span class="variable">*RSA_new_method</span><span class="operator">(</span><span class="variable">ENGINE</span> <span class="variable">*engine</span><span class="operator">);</span>
</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>An <b>RSA_METHOD</b> specifies the functions that OpenSSL uses for RSA operations. By modifying the method, alternative implementations such as hardware accelerators may be used. IMPORTANT: See the NOTES section for important information about how these RSA API functions are affected by the use of <b>ENGINE</b> API calls.</p>

<p>Initially, the default RSA_METHOD is the OpenSSL internal implementation, as returned by RSA_PKCS1_OpenSSL().</p>

<p>RSA_set_default_method() makes <b>meth</b> the default method for all RSA structures created later. <b>NB</b>: This is true only whilst no ENGINE has been set as a default for RSA, so this function is no longer recommended. This function is not thread-safe and should not be called at the same time as other OpenSSL functions.</p>

<p>RSA_get_default_method() returns a pointer to the current default RSA_METHOD. However, the meaningfulness of this result is dependent on whether the ENGINE API is being used, so this function is no longer recommended.</p>

<p>RSA_set_method() selects <b>meth</b> to perform all operations using the key <b>rsa</b>. This will replace the RSA_METHOD used by the RSA key and if the previous method was supplied by an ENGINE, the handle to that ENGINE will be released during the change. It is possible to have RSA keys that only work with certain RSA_METHOD implementations (eg. from an ENGINE module that supports embedded hardware-protected keys), and in such cases attempting to change the RSA_METHOD for the key can have unexpected results.</p>

<p>RSA_get_method() returns a pointer to the RSA_METHOD being used by <b>rsa</b>. This method may or may not be supplied by an ENGINE implementation, but if it is, the return value can only be guaranteed to be valid as long as the RSA key itself is valid and does not have its implementation changed by RSA_set_method().</p>

<p>RSA_flags() returns the <b>flags</b> that are set for <b>rsa</b>&#39;s current RSA_METHOD. See the BUGS section.</p>

<p>RSA_new_method() allocates and initializes an RSA structure so that <b>engine</b> will be used for the RSA operations. If <b>engine</b> is NULL, the default ENGINE for RSA operations is used, and if no default ENGINE is set, the RSA_METHOD controlled by RSA_set_default_method() is used.</p>

<p>RSA_flags() returns the <b>flags</b> that are set for <b>rsa</b>&#39;s current method.</p>

<p>RSA_new_method() allocates and initializes an <b>RSA</b> structure so that <b>method</b> will be used for the RSA operations. If <b>method</b> is <b>NULL</b>, the default method is used.</p>

<h1 id="THE-RSA_METHOD-STRUCTURE">THE RSA_METHOD STRUCTURE</h1>

<pre><code> <span class="variable">typedef</span> <span class="variable">struct</span> <span class="variable">rsa_meth_st</span>
 <span class="operator">{</span>
     <span class="regex">/* name of the implementation */</span>
     <span class="variable">const</span> <span class="variable">char</span> <span class="variable">*name</span><span class="operator">;</span>
 
     <span class="regex">/* encrypt */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_pub_enc</span><span class="operator">)(</span><span class="keyword">int</span> <span class="variable">flen</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*from</span><span class="operator">,</span>
                        <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*to</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">padding</span><span class="operator">);</span>
 
     <span class="regex">/* verify arbitrary data */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_pub_dec</span><span class="operator">)(</span><span class="keyword">int</span> <span class="variable">flen</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*from</span><span class="operator">,</span>
                        <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*to</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">padding</span><span class="operator">);</span>
 
     <span class="regex">/* sign arbitrary data */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_priv_enc</span><span class="operator">)(</span><span class="keyword">int</span> <span class="variable">flen</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*from</span><span class="operator">,</span>
                         <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*to</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">padding</span><span class="operator">);</span>
 
     <span class="regex">/* decrypt */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_priv_dec</span><span class="operator">)(</span><span class="keyword">int</span> <span class="variable">flen</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*from</span><span class="operator">,</span>
                         <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*to</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">padding</span><span class="operator">);</span>
 
     <span class="regex">/* compute r0 = r0 ^ I mod rsa-&gt;n (May be NULL for some implementations) */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_mod_exp</span><span class="operator">)(</span><span class="variable">BIGNUM</span> <span class="variable">*r0</span><span class="operator">,</span> <span class="variable">BIGNUM</span> <span class="variable">*I</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">);</span>
 
     <span class="regex">/* compute r = a ^ p mod m (May be NULL for some implementations) */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*bn_mod_exp</span><span class="operator">)(</span><span class="variable">BIGNUM</span> <span class="variable">*r</span><span class="operator">,</span> <span class="variable">BIGNUM</span> <span class="variable">*a</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">BIGNUM</span> <span class="variable">*p</span><span class="operator">,</span>
                       <span class="variable">const</span> <span class="variable">BIGNUM</span> <span class="variable">*m</span><span class="operator">,</span> <span class="variable">BN_CTX</span> <span class="variable">*ctx</span><span class="operator">,</span> <span class="variable">BN_MONT_CTX</span> <span class="variable">*m_ctx</span><span class="operator">);</span>
 
     <span class="regex">/* called at RSA_new */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*init</span><span class="operator">)(</span><span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">);</span>
 
     <span class="regex">/* called at RSA_free */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*finish</span><span class="operator">)(</span><span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">);</span>
 
     <span class="regex">/*
      * RSA_FLAG_EXT_PKEY        - rsa_mod_exp is called for private key
      *                            operations, even if p,q,dmp1,dmq1,iqmp
      *                            are NULL
      * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private</span> <span class="variable">match</span>
      <span class="operator">*/</span>
     <span class="keyword">int</span> <span class="variable">flags</span><span class="operator">;</span>
 
     <span class="variable">char</span> <span class="variable">*app_data</span><span class="operator">;</span> <span class="regex">/* ?? */</span>
 
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_sign</span><span class="operator">)(</span><span class="keyword">int</span> <span class="variable">type</span><span class="operator">,</span>
                     <span class="variable">const</span> <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*m</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="keyword">int</span> <span class="variable">m_length</span><span class="operator">,</span>
                     <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*sigret</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="keyword">int</span> <span class="variable">*siglen</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">);</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_verify</span><span class="operator">)(</span><span class="keyword">int</span> <span class="variable">dtype</span><span class="operator">,</span>
                       <span class="variable">const</span> <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*m</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="keyword">int</span> <span class="variable">m_length</span><span class="operator">,</span>
                       <span class="variable">const</span> <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*sigbuf</span><span class="operator">,</span> <span class="variable">unsigned</span> <span class="keyword">int</span> <span class="variable">siglen</span><span class="operator">,</span>
                       <span class="variable">const</span> <span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">);</span>
     <span class="regex">/* keygen. If NULL builtin RSA key generation will be used */</span>
     <span class="keyword">int</span> <span class="operator">(</span><span class="variable">*rsa_keygen</span><span class="operator">)(</span><span class="variable">RSA</span> <span class="variable">*rsa</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">bits</span><span class="operator">,</span> <span class="variable">BIGNUM</span> <span class="variable">*e</span><span class="operator">,</span> <span class="variable">BN_GENCB</span> <span class="variable">*cb</span><span class="operator">);</span>
 
 <span class="operator">}</span> <span class="variable">RSA_METHOD</span><span class="operator">;</span>
</code></pre>

<h1 id="RETURN-VALUES">RETURN VALUES</h1>

<p>RSA_PKCS1_OpenSSL(), RSA_PKCS1_null_method(), RSA_get_default_method() and RSA_get_method() return pointers to the respective RSA_METHODs.</p>

<p>RSA_set_default_method() returns no value.</p>

<p>RSA_set_method() returns a pointer to the old RSA_METHOD implementation that was replaced. However, this return value should probably be ignored because if it was supplied by an ENGINE, the pointer could be invalidated at any time if the ENGINE is unloaded (in fact it could be unloaded as a result of the RSA_set_method() function releasing its handle to the ENGINE). For this reason, the return type may be replaced with a <b>void</b> declaration in a future release.</p>

<p>RSA_new_method() returns NULL and sets an error code that can be obtained by <a href="../man3/ERR_get_error.html">ERR_get_error(3)</a> if the allocation fails. Otherwise it returns a pointer to the newly allocated structure.</p>

<h1 id="BUGS">BUGS</h1>

<p>The behaviour of RSA_flags() is a mis-feature that is left as-is for now to avoid creating compatibility problems. RSA functionality, such as the encryption functions, are controlled by the <b>flags</b> value in the RSA key itself, not by the <b>flags</b> value in the RSA_METHOD attached to the RSA key (which is what this function returns). If the flags element of an RSA key is changed, the changes will be honoured by RSA functionality but will not be reflected in the return value of the RSA_flags() function - in effect RSA_flags() behaves more like an RSA_default_flags() function (which does not currently exist).</p>

<h1 id="SEE-ALSO">SEE ALSO</h1>

<p><a href="../man3/RSA_new.html">RSA_new(3)</a></p>

<h1 id="HISTORY">HISTORY</h1>

<p>The RSA_null_method(), which was a partial attempt to avoid patent issues, was replaced to always return NULL in OpenSSL 1.1.1.</p>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<p>Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.</p>

<p>Licensed under the OpenSSL license (the &quot;License&quot;). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>


</body>

</html>


